<template>
	<view class="pb20">
		<custom-nav :title="'我的'" :isBack="false"></custom-nav>
		<view class="avatar-box df ac">
			<avatar
				:name="
					loginUser.name && loginUser.name.length > 2
						? loginUser.name.substr(loginUser.name.length - 2, 2)
						: loginUser.name
				"
				:width="120"
				:fontsize="30"
				avatarIcon="https://fe-static.yilife.cn/upload/images/Rectangle 428@2x.png_2023-08-23-11-22-18.png"
			></avatar>
			<view class="ml30">
				<view v-if="loginUser.name">
					<view class="f36">{{ loginUser.name }}</view>
					<view class="c97 f32">{{
						selectedCompany.tenantName
					}}</view>
				</view>
				<button v-else class="g6 default-button f32" @tap="jumpTo">
					未登录
				</button>
			</view>
		</view>
		<view class="container">
			<view
				class="flex-between list-item"
				v-for="(item, index) in menuList"
				:key="index"
				@tap="dispatchJump(item)"
			>
				<view class="w90 flex-start">
					<view class="left-icon">
						<image :src="item.icon"></image>
					</view>
					<view class="ml20 f32">{{ item.name }}</view>
				</view>
				<view class="w10 flex-end"
					><image :src="rightIcon" class="right-icon"></image
				></view>
			</view>
		</view>
	</view>
</template>

<script>
import avatar from '@/components/avatar/avatar.vue'
const rightIcon =
	'https://fe-static.yilife.cn/svg/office-software/6c06384b7872f304fe4855bf0ed3eacc.svg'
export default {
	components: { avatar },
	data() {
		return {
			rightIcon,
			selectedCompany: {},
			loginUser: {},
			menuList: [
				{
					name: '我的订单',
					icon: 'https://fe-static.yilife.cn/svg/office-software/f2a0461bae187c0d25de02bb4ffae845.svg',
					jumpType: 1, //0，默认内部小程序，1，外部小程序，
					appId: 'wx2dca4153fa9b81d9',
					jumpUrl: '/subPackagesOrder/pages/order/index/index',
				},
				{
					name: '我的服务单',
					icon: 'https://fe-static.yilife.cn/svg/office-software/fd7fe40887e42ce25d7a98b4fc69c19e.svg',
					jumpType: 1, //0，默认内部小程序，1，外部小程序，
					appId: 'wx2dca4153fa9b81d9',
					jumpUrl: '/subPackagesOrder/pages/order/serviceOrder/index',
				},
				{
					name: '我的收入',
					icon: 'https://fe-static.yilife.cn/svg/office-software/0bf108e2cb62b99d11ecc8f9b1717f64.svg',
					jumpType: 1, //0，默认内部小程序，1，外部小程序，
					appId: 'wx2dca4153fa9b81d9',
					jumpUrl: '/subPackagesMy/pages/my/income/income',
				},
				{
					name: '我的保险',
					icon: 'https://fe-static.yilife.cn/svg/office-software/9fdba9056b23228bbe23cacc9c8ab6c7.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
				{
					name: '我的钱包',
					icon: 'https://fe-static.yilife.cn/svg/office-software/a6c3db3001fe37d9c4694d4c72f6ce2a.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
				{
					name: '我要赚钱',
					icon: 'https://fe-static.yilife.cn/svg/office-software/dc602dc09899c1dc14c498fea5651564.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
				{
					name: '我要加盟',
					icon: 'https://fe-static.yilife.cn/svg/office-software/06e287f9de0a999e8c36d92a97bfdc99.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
				{
					name: '会员中心',
					icon: 'https://fe-static.yilife.cn/svg/office-software/4f14e86d3920ff4c09385624c2995bb3.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
				{
					name: '权益中心',
					icon: 'https://fe-static.yilife.cn/svg/office-software/ac48e073c15e9a47f1c9c62914af49b1.svg',
					jumpType: 0, //0，默认内部小程序，1，外部小程序，
					appId: '',
					jumpUrl: '',
				},
			],
		}
	},
	onShow() {
		this.selectedCompany = uni.getStorageSync('selectedCompany')
		this.loginUser = uni.getStorageSync('loginUser')
	},
	methods: {
		jumpTo() {
			uni.switchTab({
				url: `/pages/index/index`,
			})
		},
		/** 跳转页面 */
		dispatchJump(data) {
			const { appId, jumpType, jumpUrl } = data

			if (!jumpUrl) {
				uni.showToast({
					title: '敬请期待~',
					icon: 'none',
				})
				return
			}

			switch (jumpType) {
				case 1:
					uni.navigateToMiniProgram({
						appId: appId,
						path: jumpUrl,
					})
					break
				default:
					uni.navigateTo({
						jumpUrl,
					})
			}
		},
	},
}
</script>

<style scoped lang="scss">
.avatar-box {
	background: #fff;
	padding: 30rpx 30rpx;
	font-size: 34rpx;
}
.c97 {
	color: #979797;
}
.default-button {
	background: #fff !important;
}
.container {
	margin: 30rpx;
	padding: 0 30rpx 0 30rpx;
	background: #ffffff;
	box-shadow: 2rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.1);
	border-radius: 10rpx;
	.list-item {
		border-bottom: 2rpx #d9d9d9 solid;
		height: 140rpx;
		.left-icon {
			width: 44rpx;
			height: 44rpx;
			image {
				width: 44rpx;
				height: 44rpx;
			}
		}
		.right-icon {
			width: 16rpx;
			height: 29rpx;
		}
		&:last-child {
			border-bottom: none;
		}
	}
}
</style>
